package com.example.myapplication.tack_13;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.text.Spanned;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.tack_13.data.DetailsData;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;

public class DetailsActivity extends AppCompatActivity {
    private ImageView exit;
    private ImageView imags;

    private TextView text;
    private TextView click;
    private DetailsData data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_13_activity_details);
        Intent intent = getIntent();
        String id = intent.getStringExtra(Common.COMMON);
        init();
        exit_();
        getDetails(id);
        click_();

    }



    private void exit_() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DetailsActivity.this.finish();
            }
        });
    }

    private void click_() {
        click.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(DetailsActivity.this,PatientActivity.class);
                intent1.putExtra(Common.COMMON,data.getData().getId());
                DetailsActivity.this.startActivity(intent1);
            }
        });
    }

    private void getDetails(String id) {
        String url = "prod-api/api/hospital/hospital/"+id;
        OkHttpTool.doNetRequest(url, OkHttpTool.GET, DetailsData.class, new OkHttpTool.NetCallback() {
            @Override
            public void onSuccess(Object obj) {
                data = (DetailsData)obj;
                if(data.getCode() ==200){
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Glide.with(DetailsActivity.this).load(OkHttpTool.URL+ data.getData().getImgUrl()).into(imags);
                            String spanned = Html.fromHtml(data.getData().getBrief()).toString();
                            text.setText(spanned);

                        }
                    });
                }

            }

            @Override
            public void onFailure(String msg) {

            }
        });
    }

    private void init() {
        exit = findViewById(R.id.exit);
        imags = findViewById(R.id.imags);

        text = findViewById(R.id.text);
        click = findViewById(R.id.click);
    }
}